package com.codejiwei.flink.practice;

import com.codejiwei.flink.source.AppMarketingDataSource;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author jiwei
 * @description
 * @date 2023/5/23 9:22
 */
public class Flink_Project_AppAnalysis_By_Chanel {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(5);

        env.addSource(new AppMarketingDataSource())
//                .map(be -> Tuple2.of(be.getChannel() + "_" + be.getBehavior(), 1L))
                .map(be -> Tuple2.of(be.getBehavior(), 1L))
                .returns(Types.TUPLE(Types.STRING, Types.LONG))
                .keyBy(t -> t.f0)
                .sum(1)
                .print();

        env.execute();
    }
}
